package com.czeczek.domain.dao.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.joda.time.LocalDate;
import org.springframework.jdbc.core.RowMapper;

import com.czeczek.domain.Quote;

public class QuoteRowMapper implements RowMapper<Quote> {
	
	public static final int ID_COLUMN = 1;
	public static final int SYMBOL_COLUMN = 2;
	public static final int DATE_COLUMN = 3;
	public static final int TIME_COLUMN = 4;
	public static final int OPEN_COLUMN = 5;
	public static final int HIGH_COLUMN = 6;
	public static final int LOW_COLUMN = 7;
	public static final int CLOSE_COLUMN = 8;
	public static final int VOLUME_COLUMN = 9;
	public static final int OPEN_INT_COLUMN = 10;
	
	public Quote mapRow(ResultSet rs, int rowNum) throws SQLException {
		Quote quote = new com.czeczek.domain.Quote();
		
		quote.setQuoteId(rs.getLong(ID_COLUMN));
		quote.setSymbol(rs.getString(SYMBOL_COLUMN));
		quote.setDate(new LocalDate(rs.getDate(DATE_COLUMN).getTime()));
		//quote.setTime(new LocalTime(rs.getTime(TIME_COLUMN).getTime()));
		quote.setOpenPrice(rs.getBigDecimal(OPEN_COLUMN));
		quote.setHighPrice(rs.getBigDecimal(HIGH_COLUMN));
		quote.setLowPrice(rs.getBigDecimal(LOW_COLUMN));
		quote.setClosePrice(rs.getBigDecimal(CLOSE_COLUMN));
		quote.setVolume(rs.getBigDecimal(VOLUME_COLUMN));
		quote.setOpenInterest(rs.getBigDecimal(OPEN_INT_COLUMN).toBigInteger());
		
		return quote;
	}

}
